<template>
  <div class="inventory">
    <el-button plain type="single-number" @click="showDialog()">
      {{ btnText }}
    </el-button>
    <el-dialog
      :title="dialogTitle"
      :visible.sync="showDialogVisible"
      custom-class="revenue-code-number"
      width="63%"
    >
      <div class="el-dialog__body-bodys">
        <el-table
          :data="inventoryTableDatas"
          ref="inventoryMultipleTable"
          class="ccui-form-child-table"
          border
          :fit="true"
          max-height="800px"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column label="序号" width="55">
            <template slot-scope="scope">
              <span>{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            v-for="(item, index) in tableHeadOptions"
            :key="index"
            :prop="item.prop"
            :label="item.label"
            :min-width="item.width"
          />
          <!-- <el-table-column label="操作" width="80" fixed="right">
            <template slot-scope="{ row }">
              <el-button size="mini" type="text" @click="handlecheck(row)"
                >选择</el-button
              >
            </template>
          </el-table-column> -->
        </el-table>
        <div
          class="table-footer"
          v-if="inventoryTotal != ''"
          style="height: 30px"
        ></div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          size="mini"
          type="default-mini"
          @click="showDialogVisible = false"
          >取 消</el-button
        >
        <el-button size="mini" type="primary-font-mini" @click="handleCheck"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { selectSmpTransportForScById } from "../api/transportation-approval";

export default {
  name: "acceptListSelect",
  props: {
    btnText: {
      type: String,
      default: "选择"
    },
    dialogTitle: {
      type: String,
      default: ""
    },
    searchInputArr: {
      type: Array,
      default: () => []
    },
    tableHeadOptions: {
      type: Array,
      default: () => []
    },
    getTableList: {
      type: Function,
      default: Function
    },
    settlementForm: {
      type: Object
    }
  },
  data() {
    return {
      showDialogVisible: false,
      inventoryForm: {},
      inventoryTableDatas: [],
      inventoryTotal: 0,
      inventoryPageNoCode: 1,
      inventoryPageSize: 20,
      inventoryTableData2: [],
      dialogSelectionCheckLine: []
    };
  },
  methods: {
    showDialog() {
      if (this.settlementForm.contractCode == "") {
        this.$message({
          type: "warning",
          message: "请选择合同编号"
        });
        return;
      }
      this.showDialogVisible = true;
      selectSmpTransportForScById({
        concId: this.settlementForm.contractId
      }).then(res => {
        this.inventoryTableDatas = res.data.data;
        this.inventoryTableDatas.forEach(item => {
          item.currentNum = item.currentNum.toFixed(3);
          item.currentUnitPriceIncludeTax =
            item.currentUnitPriceIncludeTax.toFixed(2);
        });
      });
      //   this.inventoryGetMcConcBill();
    },
    // inventoryGetMcConcBill() {
    //   let params = {
    //     pageNo: this.inventoryPageNoCode,
    //     pageSize: this.inventoryPageSize,
    //     ...this.inventoryForm
    //   };
    //   this.getTableList(params).then(res => {
    //     // this.inventoryTableDatas = res.data.data.rows;
    //     // this.inventoryTotal = res.data.data.recordsTotal;
    //     // this.inventoryPageNoCode = res.data.data.pageNo;
    //   });
    // },
    inventoryHandleCurrentChange(val) {
      this.inventoryPageNoCode = val;
      //   this.inventoryGetMcConcBill();
    },
    inventorySearch(searchData) {
      this.inventoryPageNoCode = 1;
      this.inventoryForm = searchData;
      //   this.inventoryGetMcConcBill();
    },
    inventorySelectTable(val) {
      this.inventoryTableData2 = val;
    },
    inventoryDeleteTable(e) {
      this.inventoryTableData2 = this.inventoryTableData2.filter(
        item => item.id !== e.id
      );
      let filterArr = this.inventoryTableData2.filter(item => item.id !== e.id);
      this.$refs.inventoryMultipleTable.clearSelection();
      filterArr.forEach(row => {
        this.$refs.inventoryMultipleTable.toggleRowSelection(row);
      });
    },
    inventoryConfirm() {
      this.showDialogVisible = false;
      this.$emit("numrow", this.inventoryTableData2);
    },
    handleCheck() {
      this.$emit("numrow", this.dialogSelectionCheckLine);
      this.$refs["inventoryMultipleTable"].clearSelection();
      this.showDialogVisible = false;
    },
    handleSelectionChange(selection) {
      this.dialogSelectionCheckLine = JSON.parse(JSON.stringify(selection));
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/ .el-table {
  /deep/ th {
    padding: 0;
    height: 36px;
    line-height: 36px;
  }

  .el-table__body {
    .cell {
      height: 36px;
      line-height: 36px;
    }
  }
}
.inventory {
  display: inline-block;
  & + .inventory {
    margin-left: 10px;
  }
}
/deep/ .revenue-code-number .el-dialog__body .el-dialog__body-bodys {
  .bodys-right {
    padding: 0;
    width: 400px;
  }
}
/deep/ .revenue-code-number .el-dialog__body {
  width: 96%;
}
/deep/ .el-table td,
.el-table th {
  padding: 0 !important;
}
/deep/ .el-table--scrollable-y .el-table__body-wrapper {
  max-height: 425px !important;
}
</style>
